package com.uifuture;

import io.netty.handler.codec.marshalling.*;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.MarshallingConfiguration;


//ByteArrayOutputStream可以捕获内存缓冲区的数据输出字节数组，ByteArrayInputStream可以读内存中的字节数组转换为输入流

/**
 * @Author:LiangTao
 * @Description:
 * @Date: Created in 16:29 2018/5/27.
 */
public final class MarshallingCodeCFactory {

    //解码
    public static MarshallingDecoder buildMarshallingDecoder() {
        final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
        final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
        marshallingConfiguration.setVersion(5);//干什么？？？
        //这应该是一种设计模式中常用的命名方式？？？
        UnmarshallerProvider provider = new DefaultUnmarshallerProvider(marshallerFactory, marshallingConfiguration);
        MarshallingDecoder marshallingDecoder = new MarshallingDecoder(provider, 1024 * 1024 * 1);//单个信息序列化最大长度，超过拒绝处理
        return marshallingDecoder;
    }

    //编码
    public static MarshallingEncoder buildMarshallingEncoder() {
        final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
        final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration();
        marshallingConfiguration.setVersion(5);
        MarshallerProvider provider = new DefaultMarshallerProvider(marshallerFactory, marshallingConfiguration);
        MarshallingEncoder marshallingEncoder = new MarshallingEncoder(provider);
        return marshallingEncoder;
    }
}
